<title>视频系统</title>
<link rel="stylesheet" type="text/css" href="/public/admin/layui_extends/formSelects-v4.css"/>
  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">视频系统</a>
      <!--<a><cite>视频系统</cite></a>-->
      <a><cite>视频列表</cite></a>
    </div>
  </div>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">视频ID</label>
            <div class="layui-input-inline">
              <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-inline">
              <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-inline">
            <label class="layui-form-label">栏目</label>
            <div class="layui-input-inline">
              <script type="text/html" template lay-url="/admin/video/get_small_column_list"  lay-done="layui.data.done(d);" >
                <select name="column_id" lay-filter="search_column_id" lay-search="">
                  <option value="">全部栏目</option>
                  {{# layui.each(d.data,function(index,item){ }}
                  <option value="{{item.id}}">{{ item.name }}</option>
                  {{# }); }}
                </select>
              </script>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
              <script type="text/html" template >
                <select name="cate_id" xm-select="search_cate_id" xm-select-radio="" ></select>
              </script>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">上映时间</label>
            <div class="layui-input-inline">
              <script type="text/html" template >
                <select name="video_time_id" xm-select="search_video_time_id"  xm-select-radio="" ></select>
              </script>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">地区</label>
            <div class="layui-input-inline">
              <script type="text/html" template >
                <select name="address_id" xm-select="search_address_id" xm-select-radio=""></select>
              </script>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">显示状态</label>
            <div class="layui-input-block">
              <select name="status">
                <option value="">全部</option>
                <option value="1">已发布</option>
                <option value="2">待审核</option>
                <option value="3">已拒绝</option>
              </select>
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-video_small-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
         <!-- <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>-->
          <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
        </div>
        <table id="LAY-video_small-list" lay-filter="LAY-video_small-list"></table>
        <script type="text/html" id="buttonTpl">
          {{#  if(d.status==1){ }}
            <button class="layui-btn  layui-btn-primary layui-btn-xs">已发布</button>
          {{#  } else if(d.status ==2 ) { }}
          <button class="layui-btn  layui-btn-xs">待审核</button>
          {{#  } else { }}
            <button class="layui-btn  layui-btn-xs layui-btn-danger" title="点击查看拒绝原因" onclick='javascript:layer.alert("{{d.refuse_memo}}")'>已拒绝</button>
          {{#  } }}
        </script>
        <script type="text/html" id="fm_imgTpl">
          {{#  if(d.fm_img){ }}
          <img style="display: inline-block; width: 50%; height: 100%;"  class="path{{d.id}}"   src= "{{d.http}}{{ d.fm_img }}" onclick='show_img("{{d.id}}")'>
          {{#  } else { }}

          {{#  } }}
        </script>
        <script type="text/html" id="table-content-list">
          {{# if(d.status !=1){ }}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
          {{#  } }}
          <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
        </script>
      </div>
    </div>
  </div>

  <script>
    function show_img(id) {
      var path=$('.path'+id).attr('src');
      layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
      //  area: '516px',
        skin: 'layui-layer-nobg', //没有背景色
        shadeClose: true,
        content: '<img src="'+path+'" style="width: 100%;">'
      })
    }
  layui.use('video', layui.factory('video')).use(['admin', 'video', 'table'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,view = layui.view
    ,table = layui.table
    ,form = layui.form;
    
    form.render(null, 'app-content-list');
    //监听显示隐藏
    form.on('switch(statusDemo)', function(obj){
      var status=2;
      if(obj.elem.checked==true){
        status=1;
      }else{
        status=2;
      }
      $.ajax({
        type: 'POST',
        url: '/admin/video/check_status_small',
        headers: {token: '4b36adc7ff355357'},
        dataType: "json",
        data: {id:this.value,status:status},
        success: function(data){
          table.reload('LAY-video_small-list');
          layer.msg(data.msg);
        }

      });
    });
    //监听搜索
    form.on('submit(LAY-app-video_small-search)', function(data){
      var field = data.field;
      
      //执行重载
      table.reload('LAY-video_small-list', {
        where: field
        ,page: {
          curr: 1 //重新从第 1 页开始
        }
      });
    });
    
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-video_small-list')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }
        var ids='';
        for(var i=0;i<checkData.length;i++){
          ids+=checkData[i].id+',';
        }
        layer.confirm('确定删除吗？', function(index) {
          
          //执行 Ajax 后重载
          admin.req({
            url: '/admin/video/del_video_small' //实际使用请改成服务端真实接口
            ,type: 'post'
            ,headers: {token: '4b36adc7ff355357'}
            ,data: {id:ids}
            ,done: function(res){
              layer.msg(res.msg);
              //table.reload('LAY-video-list');
              table.reload('LAY-video_small-list', {
                page: {
                  curr: 1 //重新从第 1 页开始
                }
              });
            }
          });

          //layer.msg('已删除');
        });
      }
      
      //添加
      ,add: function(othis){
        admin.popup({
          title: '添加小视频'
          ,area: ['100%', '100%']
          ,id: 'LAY-popup-content-add'
          ,success: function(layero, index){
            view(this.id).render('video/video_smallform').done(function(){
              //加载模块
              layui.use(['jquery', 'formSelects'], function(){
                var formSelects = layui.formSelects;
                formSelects.render();
              });
              layui.use('laydate', function() {
                var laydate = layui.laydate;
                laydate.render({
                  elem: '#test6'
                  , type: 'datetime'
                  ,min:0
                });
              });
              jQuery(function() {
                var $ = jQuery,
                        // 优化retina, 在retina下这个值是2
                        ratio = window.devicePixelRatio || 1,

                        // 缩略图大小
                        thumbnailWidth = 100 * ratio,
                        thumbnailHeight = 100 * ratio,

                        // Web Uploader实例
                        uploader;
                // 初始化Web Uploader
                uploader = WebUploader.create({
                  // 自动上传。
                  auto: true,
                  duplicate:true,
                  formData: {upload_path:'/uploads/video_fm',file_type:'image'},
                  compress:false,
                  // swf文件路径
                  swf: '/public/webuploader/Uploader.swf',
                  // 文件接收服务端。
                  server: 'http://jieshuodiapi.com/image.php',
                  // 选择文件的按钮。可选。
                  // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                  pick: '#filePicker',
                  // 只允许选择文件，可选。
                  accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png,webp',
                    mimeTypes: 'image/*'
                  }
                });

                // 当有文件添加进来的时候
                uploader.on( 'fileQueued', function( file ) {
                  // 创建缩略图
                  uploader.makeThumb( file, function( error, src ) {
                    if ( error ) {
                      $('#filePicker img').replaceWith('<span>不能预览</span>');
                      return;
                    }

                    $('#filePicker img').attr( 'src', src );
                  }, thumbnailWidth, thumbnailHeight );
                });

                // 文件上传过程中创建进度条实时显示。
                uploader.on( 'uploadProgress', function( file, percentage ) {
                  layer.load(1, {shade: [0.8, '#393D49']})//上传loading
                });

                // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                uploader.on( 'uploadSuccess', function( file ,response) {
                  //$( '#'+file.id ).addClass('upload-state-done');
                  if(response.code==0 && response.src){
                    layer.msg('上传成功');
                    $('.path').val(response.src);
                  }else{
                    layer.alert('上传失败');
                  }
                });
                // 文件上传失败，现实上传出错。
                uploader.on( 'uploadError', function( file ) {
                  layer.closeAll('loading'); //关闭loading
                  //$error.text('上传失败');
                  layer.alert('上传失败');
                });

                // 完成上传完了，成功或者失败，先删除进度条。
                uploader.on( 'uploadComplete', function( file ) {
                  layer.closeAll('loading'); //关闭loading
                });
              });
              jQuery(function() {
                var $ = jQuery,
                        // 优化retina, 在retina下这个值是2
                        ratio = window.devicePixelRatio || 1,

                        // 缩略图大小
                        thumbnailWidth = 100 * ratio,
                        thumbnailHeight = 100 * ratio,

                        // Web Uploader实例
                        uploader;
                // 初始化Web Uploader
                uploader = WebUploader.create({
                  // 自动上传。
                  auto: true,
                  duplicate:true,
                  formData: {upload_path:'/uploads/video_fm',file_type:'image'},
                  compress:false,
                  // swf文件路径
                  swf: '/public/webuploader/Uploader.swf',
                  // 文件接收服务端。
                  server: 'http://jieshuodiapi.com/image.php',
                  // 选择文件的按钮。可选。
                  // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                  pick: '#filePicker1',
                  // 只允许选择文件，可选。
                  accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png,webp',
                    mimeTypes: 'image/*'
                  }
                });

                // 当有文件添加进来的时候
                uploader.on( 'fileQueued', function( file ) {
                  // 创建缩略图
                  uploader.makeThumb( file, function( error, src ) {
                    if ( error ) {
                      $('#filePicker1 img').replaceWith('<span>不能预览</span>');
                      return;
                    }

                    $('#filePicker1 img').attr( 'src', src );
                  }, thumbnailWidth, thumbnailHeight );
                });

                // 文件上传过程中创建进度条实时显示。
                uploader.on( 'uploadProgress', function( file, percentage ) {
                  layer.load(1, {shade: [0.8, '#393D49']})//上传loading
                });

                // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                uploader.on( 'uploadSuccess', function( file ,response) {
                  //$( '#'+file.id ).addClass('upload-state-done');
                  if(response.code==0 && response.src){
                    layer.msg('上传成功');
                    $('.rec_path').val(response.src);
                  }else{
                    layer.alert('上传失败');
                  }
                });
                // 文件上传失败，现实上传出错。
                uploader.on( 'uploadError', function( file ) {
                  layer.closeAll('loading'); //关闭loading
                  //$error.text('上传失败');
                  layer.alert('上传失败');
                });

                // 完成上传完了，成功或者失败，先删除进度条。
                uploader.on( 'uploadComplete', function( file ) {
                  layer.closeAll('loading'); //关闭loading
                });
              });
              var m3u8_status=2;
              var uploader = WebUploader.create({
                // swf文件路径
                swf: 'public/webuploader/Uploader.swf',
                auto: true,
                duplicate:true,
                formData: {upload_path:'/uploads/video',file_type:'video',m3u8_status:m3u8_status},
                // 文件接收服务端。
                server: 'http://jieshuodiapi.com/image.php',
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#picker',
                //chunked : false, // 是否分片
                //duplicate:true,//去重， 根据文件名字、文件大小和最后修改时间来生成hash Key.
                // chunkSize : 52428 * 100, // 分片大小， 5M
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                resize: false
              });
              $('.webuploader-pick:eq(2)').css('background','#00b7ee');
              $list = $('#thelist');
              // 当有文件被添加进队列的时候
              uploader.on( 'fileQueued', function( file ) {
                $list.append( '<div id="' + file.id + '" class="item">' +
                        '</div>' );
              });

              // 文件上传过程中创建进度条实时显示。
              uploader.on( 'uploadProgress', function( file, percentage ) {
                var $li = $( '#'+file.id ),
                        $percent = $li.find('.progress .progress-bar');

                // 避免重复创建
                if ( !$percent.length ) {
                  $percent = $('<div class="progress progress-striped active">' +
                          '<div class="progress-bar" role="progressbar" style="width: 0%;">' +
                          '</div>' +
                          '</div>').appendTo( $li ).find('.progress-bar');
                }

                $li.find('p.state').text('上传中');

                $percent.css( 'width', percentage * 100 + '%' );
                //layer.load(1, {shade: [0.8, '#393D49']})//上传loading
              });
              uploader.on( 'uploadSuccess', function( file,response ) {
                if(response.code==0 && response.src){
                  layer.msg('上传成功');
                  $('.url').val(response.src);
                  $('.edit_m3u8_time').val(response.m3u8_time);
                  $('.video_time').val(response.video_time);
                  var http_url=$('.http').val();
                  $('.video_url').attr('src',http_url+response.src);
                  var videoObject = {
                    container: '#video',//“#”代表容器的ID，“.”或“”代表容器的class
                    variable: 'player',//该属性必需设置，值等于下面的new chplayer()的对象
                    autoplay:true,//自动播放
                    video:http_url+response.src//视频地址
                  };
                  var player=new ckplayer(videoObject);
                }else{
                  layer.alert('上传失败');
                }
                $( '#'+file.id ).find('p.state').text('已上传');
                //layer.closeAll('loading'); //关闭loading
              });

              uploader.on( 'uploadError', function( file ) {
                $( '#'+file.id ).find('p.state').text('上传出错');
                //layer.closeAll('loading'); //关闭loading
              });

              uploader.on( 'uploadComplete', function( file ) {
                $( '#'+file.id ).find('.progress').fadeOut();
              });
              form.render(null, 'layuiadmin-video_small-form-list');

              //监听提交
              form.on('submit(layuiadmin-video_small-form-submit)', function(data){
                var field = data.field; //获取提交的字段

                //提交 Ajax 成功后，关闭当前弹层并重载表格
                admin.req({
                  url: '/admin/video/add_video_small' //实际使用请改成服务端真实接口
                  ,type: 'post'
                  ,headers: {token: '4b36adc7ff355357'}
                  ,data: field,
                 done: function(res){
                   if(res.code==0){
                     layer.close(index);
                   }
                    layer.msg(res.msg);
                    layui.table.reload('LAY-video_small-list'); //重载表格
                  }
                });

                //layer.close(index); //执行关闭
              });
            });
          }

        });
      }
    }; 

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    form.on('select(search_column_id)', function(data){
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('search_video_time_id', 'server', {
          url: '/admin/video/get_video_time_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('search_cate_id', 'server', {
          url: '/admin/video/get_small_cate_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('search_address_id', 'server', {
          url: '/admin/video/get_address_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });

    });
  });

  layui.data.done = function(d){
    layui.use(['form'], function(){
      var form = layui.form;
      form.render(); //渲染该模板下的动态表单
    });
  };

  </script>
